<template>
	<view class="mainpadding2" style="padding-bottom: 150rpx;">
		<view class="ffffff radius mainpadding_top" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="flexleft">
					<image :src="item.user.avatar_text" class="headimg margin_right" mode=""></image>
					<view class="">
						<view class="xiaohei titletext">{{item.user.username}}</view>
						<view class="xiaohui titletext margin_top1">{{item.user.mobile}}</view>
					</view>
				</view>
				<u-icon name="phone-fill" color="#c1282e" size="28" @click="makePhoneCall(item.user.mobile)"></u-icon>
			</view>
			<view class="flexbetween">
				<view class="xiaohui main_size margin_top">{{item.createtime_text}}</view>
				<u-icon name="trash" color="#c1282e" size="28" @click="itemid=item.id;modal.modalShow=true"></u-icon>
			</view>
			<view class="xiaohui main_size margin_top">就职企业：{{item.company.name}}</view>
			<view class="xiaohui main_size margin_top">月份：{{item.mouth_text}}</view>
		</view>
		<view class="mainpadding posibottom">
			<view class="submitbtn" @click="show=true">添加成员</view>
		</view>
		<u-modal :show="show" title="添加成员" confirmText="确认" @confirm="chongzhi" cancelText="取消" confirmColor="#c1282e"
			@cancel="chongzhicancel" showCancelButton>
			<view class="slot-content" style="width: 600rpx;">
				<view class="flexbetween margin_top">
					<view class="main_size bold hei_text" style="width: 150rpx;">身份证号：</view>
					<input type="text" class="textright" placeholder="请输入身份证号" v-model="idcard">
				</view>
				<view class="flexbetween margin_top" @click="lxShow=true">
					<view class="main_size bold hei_text" style="width: 150rpx;">企业：</view>
					<view class="flexright">

						<input type="text" class="textright" placeholder="请选择企业" disabled="" v-model="fwtype_text">
						<u-icon name="arrow-right" color="#999" size="20"></u-icon>
					</view>
				</view>
			</view>
		</u-modal>
		<u-picker :show="lxShow" :columns="lxList" title="请选择企业" @cancel="lxShow=false" @confirm="lxconfirm"
			keyName="name"></u-picker>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				idcard: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				lxList: [],
				fwtype_text: "",
				fwtype_id: "",
				lxShow: false,
				itemid:"",
				modal:{
					modalShow:false,
					title:"是否确认退出删除当前成员？",
				}
			}
		},
		onLoad() {
			this.init()
			this.getfuwl()
		},
		methods: {
			modalSure(){
				if(this.modal.title=="是否确认退出删除当前成员？"){
					this.delitem(this.itemid)
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			delitem(id) {
				httpRequest.request('/api/user/delZpUser', 'GET', {
					id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				})
			},
			getfuwl() {
				httpRequest.request('/api/index/companyindex', 'GET', {}, false, false, true).then(res => {
					this.lxList.push(res.data)
				})
			},
			lxconfirm(e) {
				this.fwtype_id = e.value[0].id
				this.fwtype_text = e.value[0].name
				this.lxShow = false
			},
			makePhoneCall(phone_num) {

				uni.makePhoneCall({
					phoneNumber: phone_num,
				});
			},
			chongzhicancel() {
				this.idcard = ""
				this.show = false
			},
			chongzhi() {
				if (this.idcard == "") {
					httpRequest.toast("请输入身份证号")
					return false
				}
				if (this.fwtype_id == "") {
					httpRequest.toast("请选择企业")
					return false
				}
				this.show = false
				httpRequest.request("/api/user/addZpUser", 'GET', {
					idcard: this.idcard,
					company_id: this.fwtype_id,
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.chongzhicancel()
						this.init()
					}
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/zpUserIndex', 'GET', {
					page: page || 1,
					limit: _this.limit,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>